// ml278
// Copyright (C) 2008 Bjørn Øivind Bjørnsen, Aleksander Gjermundsen, Knut Andre Tidemann, Thomas Hansen
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

#ifndef __GUIMENU_H
#define __GUIMENU_H

#include "Ogre.h"
#include "QuickGUI/include/QuickGUI.h"
#include "keybindingsmanager.h"
#include <vector>

using namespace QuickGUI;

class Application;

/**
 * Implementation of a simple GUI-menu.
 * Provides a simple keybinding interface, in addition to some standard options.
*/
class GUIMenu
{
        typedef void (GUIMenu::*evtHndlr)(const EventArgs&);
protected: 
        Sheet* mSheet;			/**< root sheet object, every component is created from this */
        GUIManager* mGUIManager;	/**< GUI Manager object */
        Window* mMenuWindow;		/**< the main menu window */
        Window* mOptionsWindow;		/**< the options window, child of the main menu window */
	Window* mAboutWindow;		/**< the about window, child of the main menu window */
        Window* mKeyBindingsWindow;	/**< the key bindings window, child of the options window */
        Size* mWindowSize;		/**< size of the rendering window */
        KeyBindingsManager *mKeyMgr;	/**< key bindings manager instance */

	// Options-menu
	ComboBox* mOptionsCameraAngleCombo;		/**< combobox for the camera angle in the options window */
	ComboBox* mOptionsKeysOverlayCombo;		/**< combobox for the keys overlay in the options window */
	ComboBox* mOptionsStatsOverlayCombo;		/**< combobox for the stats overlay in the options window */
	ComboBox* mOptionsPolygonModeCombo;		/**< combobox for the polygon mode in the options window */
	ComboBox* mOptionsShipControlCombo;		/**< combobox for ship control in the options window */
	ComboBox* mOptionsTextureFilteringCombo;	/**< combobox for the texture filtering in the options window */

        std::vector<TextBox*> mKeyTextBoxes;		/**< vector with textboxes in the key bindings window, indexed by keybindings */
        std::vector<evtHndlr> mTextBoxEvtHndlrs;	/**< vector with function-fointers to the event-handlers for the mKeyTextBoxes*/

        Application *mApplication;			/**< application in which the menu is created */
        Ogre::SceneManager *mSceneMgr;			/**< scenemanager used for drawing */
        Ogre::Camera *mCamera;				/**< camera used in the application */
        bool mIsVisible;				/**< true if the menu is visible */

        std::vector<OIS::KeyCode> mKeySettings;		/**< local storage of keybindings */

        void initGUI();
        void createMainMenu();
        void createOptionsMenu();
	void createAboutWindow();
        void createKeyBindingsMenu();
	void syncKeyBindingsToManager();

	void keyTextBoxChanged(const EventArgs&, ml278::KeyBindings);

        void evtHndlr_resumeApplication(const EventArgs&);
        void evtHndlr_optionsMainMenuButton(const EventArgs&);
	void evtHndlr_aboutMainMenuButton(const EventArgs&);
        void evtHndlr_exitApplication(const EventArgs&);
        void evtHndlr_optionsExitButton(const EventArgs&);
	void evtHndlr_aboutExitButton(const EventArgs&);
        void evtHndlr_keyBindingsOkButton(const EventArgs&);
	void evtHndlr_keyBindingsCancelButton(const EventArgs&);
	void evtHndlr_keyBindingsDefaultsButton(const EventArgs&);
        void evtHndlr_keyEditorButton(const EventArgs&);
	void evtHndlr_optionsCameraAngleCombo(const EventArgs&);
	void evtHndlr_optionsKeysOverlayCombo(const EventArgs&);
	void evtHndlr_optionsStatsOverlayCombo(const EventArgs&);
	void evtHndlr_optionsPolygonModeCombo(const EventArgs&);
	void evtHndlr_optionsShipControlCombo(const EventArgs&);
	void evtHndlr_optionsTextureFilteringCombo(const EventArgs&);

	void evtHndlr_keyForwardChanged(const EventArgs&);
        void evtHndlr_keyBackwardChanged(const EventArgs&);
        void evtHndlr_keyYawLeftChanged(const EventArgs&);
	void evtHndlr_keyYawRightChanged(const EventArgs&);
	void evtHndlr_keyPitchUpChanged(const EventArgs&);
	void evtHndlr_keyPitchDownChanged(const EventArgs&);
	void evtHndlr_keyScreenshotChanged(const EventArgs&);
	void evtHndlr_keyKeysOverlayChanged(const EventArgs&);
	void evtHndlr_keyStatsOverlayChanged(const EventArgs&);
	void evtHndlr_keySwitchTextureFilteringChanged(const EventArgs&);
	void evtHndlr_keySwitchPolygonModeChanged(const EventArgs&);
	void evtHndlr_keyCameraFirstPersonChanged(const EventArgs&);
	void evtHndlr_keyCameraThirdPersonChanged(const EventArgs&);
	void evtHndlr_keyCameraFreeroamChanged(const EventArgs&);
	void evtHndlr_keyToggleGUIChanged(const EventArgs&);
	void evtHndlr_keyQuitChanged(const EventArgs&);
public:
        GUIMenu(Application *application, Ogre::SceneManager *sceneMgr, Ogre::Camera *camera, KeyBindingsManager *keyMgr, bool hidden);
        ~GUIMenu();

        //bool isHidden();
        void hide();
        void show();
        bool isVisible();
        void injectTime(Ogre::Real);
        void injectKeyDown(KeyCode);
        void injectKeyUp(KeyCode);
        void injectChar(char);
        void injectMouseMove(int, int); 
        void injectMouseButtonDown(const MouseButtonID&);
        void injectMouseButtonUp(const MouseButtonID&);
};

#endif // #ifndef __GUIMENU_H
